class Cadastro::Contato::LogradourosController < ApplicationController
  # GET /logradouro
  # GET /logradouro.xml
  def index
    @logradouros  = Logradouro.find(:all).paginate :page => params[:pagina], :per_page => 15
    @bairros = Bairro.find(:all)
    @tipo_logradouros = TipoLogradouro.find(:all)
    @situacoes = Situacao.find(:all)
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @logradouros }
    end
  end

  # GET /logradouro/1
  # GET /logradouro/1.xml
  def show
    @logradouro = Logradouro.find(params[:id])
    @bairros = Bairro.find(:all)
    @tipo_logradouros = TipoLogradouro.find(:all)
    @situacoes = Situacao.find(:all)
    @field_disable = true
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @logradouro }
    end
  end

  # GET /logradouro/new
  # GET /logradouro/new.xml
  def new
    @logradouro = Logradouro.new
    @field_disable = false
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @logradouro }
    end
  end

  # GET /logradouro/1/edit
  def edit
    @logradouro = Logradouro.find(params[:id])
    @field_disable = false
  end

  # POST /logradouro
  # POST /logradouro.xml
  def create
    @logradouro = Logradouro.new(params[:logradouro])
    respond_to do |format|
      if @logradouro.save
        flash[:success] = 'Logradouro criado com sucesso.'
        format.html { redirect_to(@logradouro) }
        format.xml  { render :xml => @logradouro, :status => :created, :location => @logradouro }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @logradouro.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /logradouro/1
  # PUT /logradouro/1.xml
  def update
    @logradouro = Logradouro.find(params[:id])
    respond_to do |format|
      if @logradouro.update_attributes(params[:logradouro])
        flash[:success] = 'Logradouro atualizado com sucesso.'
        format.html { redirect_to(@logradouro) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @logradouro.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /logradouro/1
  # DELETE /logradouro/1.xml
  def destroy
    @logradouro = Logradouro.find(params[:id])
    respond_to do |format|
      if @logradouro.destroy
        flash[:success] = 'Logradouro excluído com sucesso.'
        format.html { redirect_to(logradouros_path) }
        format.xml  { head :ok }
      end
    end
  end
end
